package GUI;

import static java.awt.event.KeyEvent.VK_B;
import static java.awt.event.KeyEvent.VK_DOWN;
import static java.awt.event.KeyEvent.VK_F;
import static java.awt.event.KeyEvent.VK_L;
import static java.awt.event.KeyEvent.VK_LEFT;
import static java.awt.event.KeyEvent.VK_PAGE_DOWN;
import static java.awt.event.KeyEvent.VK_PAGE_UP;
import static java.awt.event.KeyEvent.VK_RIGHT;
import static java.awt.event.KeyEvent.VK_UP;

import java.awt.Frame;
import java.awt.event.*;

import javax.media.opengl.awt.GLCanvas;

import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.FPSAnimator;


/**
 * this should just be a frame with a panel. the panel with display everything for the game.
 * 
 * @author kris
 *
 */
public class GameWindow extends Frame implements KeyListener, MouseListener, MouseMotionListener
{
	private static final long serialVersionUID = 1L;

	private static GameRenderer zdr;

	private static String FRAME_TITLE = "ZDefence";
	private static int FRAME_WIDTH = 640;
	private static int FRAME_HEIGHT = 480;
	private static final int FPS = 60;


	public GameWindow()
	{
		zdr = new GameRenderer();

		setTitle(FRAME_TITLE);
		setSize(FRAME_WIDTH, FRAME_HEIGHT);
		//setResizable(false);

		GLCanvas canvas = new GLCanvas();

		final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);

		canvas.addGLEventListener(zdr);
		canvas.addKeyListener(this);
		canvas.addMouseListener(this);
		canvas.addMouseMotionListener(this);

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				animator.stop();
				System.exit(0);
			}
		});

		add(canvas);

		setVisible(true);
		animator.start();
		canvas.requestFocus();
	}

	@Override
	public void keyPressed(KeyEvent key) 
	{
		switch (key.getKeyCode()) 
		{
		case KeyEvent.VK_ESCAPE:
			System.exit(0);
			break;
		case KeyEvent.VK_Q: //move camera left
			zdr.camera.moveEye(0.0f, 0.0f, 0.0f);
			break;
		case KeyEvent.VK_E: //move camera left
			zdr.camera.moveEye(-0.0f, 0.0f, 0.0f);
			break;
		case KeyEvent.VK_W: //move camera foreward
			zdr.camera.moveEye(0.0f, 0.0f, -0.2f);
			zdr.camera.lookAt(0.0f, 0.0f, -0.2f);
			break;
		case KeyEvent.VK_S: //move camera backward
			zdr.camera.moveEye(0.0f, 0.0f, 0.2f);
			zdr.camera.lookAt(0.0f, 0.0f, 0.2f);
			break;
		case KeyEvent.VK_A:
			zdr.camera.moveEye(-0.2f, 0.0f, 0.0f);
			zdr.camera.lookAt(-0.2f, 0.0f, 0.0f);
			break;
		case KeyEvent.VK_D: 
			zdr.camera.moveEye(0.2f, 0.0f, 0.0f);
			zdr.camera.lookAt(0.2f, 0.0f, 0.0f);
			break;
		case KeyEvent.VK_Z: //move camera down
			break;
		case KeyEvent.VK_X: //move camera up
			break;
		}
	}


	@Override
	public void keyReleased(KeyEvent key) 
	{

	}

	@Override
	public void keyTyped(KeyEvent key) 
	{

	}

	@Override
	public void mouseDragged(MouseEvent mouse) 
	{

	}

	@Override
	public void mouseMoved(MouseEvent mouse) 
	{

	}

	@Override
	public void mouseClicked(MouseEvent mouse) 
	{

	}

	@Override
	public void mouseEntered(MouseEvent mouse) 
	{

	}

	@Override
	public void mouseExited(MouseEvent mouse) 
	{

	}

	@Override
	public void mousePressed(MouseEvent mouse) 
	{

	}

	@Override
	public void mouseReleased(MouseEvent mouse) 
	{

	}
}
